<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="STM32CubeMX SPI ST7789">
    <meta name="description" content="本篇详细的记录了如何使用STM32CubeMX配置STM32L431RCT6的硬件SPI外设与ST7789通信，驱动16bit TFT-LCD 屏幕。


0. 前言我的一些个人观点：

学习 SPI 外设驱动LCD屏幕没有必要手写驱动，学">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>STM32CubeMX_17 | 使用硬件SPI驱动TFT-LCD（ST7789） | Mculover666</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>
    
<meta name="generator" content="Hexo 4.2.1"><link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">Mculover666</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="" class="waves-effect waves-light">

      
      <i class="fas fa-list" style="zoom: 0.6;"></i>
      
      <span>系列教程</span>
      <i class="fas fa-chevron-down" aria-hidden="true" style="zoom: 0.6;"></i>
    </a>
    <ul class="sub-nav menus_item_child ">
      
      <li>
        <a href="/posts/578764034/">
          
          <span>STM32CubeMX</span>
        </a>
      </li>
      
    </ul>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="https://blog.csdn.net/Mculover666" target="_blank" rel="noopener" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>CSDN</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/download" class="waves-effect waves-light">
      
      <i class="fas fa-download" style="zoom: 0.6;"></i>
      
      <span>资源下载</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">Mculover666</div>
        <div class="logo-desc">
            
            嵌入式 STM32 物联网领域的教程及精彩内容分享
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="javascript:;">
			
				<i class="fa-fw fas fa-list"></i>
			
			系列教程
			<span class="m-icon"><i class="fas fa-chevron-right"></i></span>
		</a>
            <ul  style="background:  ;" >
              
                <li>   
				
                  <a href="/posts/578764034/ " style="margin-left:75px";>
				  
		          <span>STM32CubeMX</span>
                  </a>
                </li>
               
            </ul>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="https://blog.csdn.net/Mculover666" target="_blank" rel="noopener" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			CSDN
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/download" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-download"></i>
			
			资源下载
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/Mculover666" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>

        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/Mculover666" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/3.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">STM32CubeMX_17 | 使用硬件SPI驱动TFT-LCD（ST7789）</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        height: calc(100vh - 250px);
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/STM32CubeMX-TFT-LCD-SPI%E6%80%BB%E7%BA%BF/">
                                <span class="chip bg-color">STM32CubeMX TFT-LCD SPI总线</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/STM32CubeMX/" class="post-category">
                                STM32CubeMX
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2019-08-07
                </div>
                

                

                

                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>

        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <p>本篇详细的记录了如何使用STM32CubeMX配置STM32L431RCT6的硬件SPI外设与ST7789通信，驱动16bit TFT-LCD 屏幕。</p>
<a id="more"></a>

<h1 id="0-前言"><a href="#0-前言" class="headerlink" title="0. 前言"></a>0. 前言</h1><p>我的一些个人观点：</p>
<blockquote>
<p>学习 SPI 外设驱动LCD屏幕没有必要手写驱动，学习这部分代码的目的是为了了解TFT-LCD的工作原理，每个像素点是如何显示的，<strong>不要花过多的精力在弄明白每个命令的意思</strong>，建议基于本驱动，学习一下打点，画线算法，画圆算法，画多边形算法等等，还可以学习显示英文字符，中文字符，最后还可以移植STemwin显示界面等等好玩的东西~</p>
</blockquote>
<p><img src="http://mculover666.cn/image/20190830/uNWWafiL7nsd.png?imageslim" alt="mark"></p>
<p><img src="http://mculover666.cn/image/20190830/AE6zUCi3kdTR.png?imageslim" alt="mark"></p>
<p><img src="http://mculover666.cn/image/20190830/H63SNPAj4yeq.png?imageslim" alt="mark"></p>
<h1 id="1-准备工作"><a href="#1-准备工作" class="headerlink" title="1. 准备工作"></a>1. 准备工作</h1><h2 id="硬件准备"><a href="#硬件准备" class="headerlink" title="硬件准备"></a>硬件准备</h2><ul>
<li>开发板<br>首先需要准备一个开发板，这里我准备的是STM32L4的开发板（BearPi）：</li>
</ul>
<p><img src="http://mculover666.cn/image/20190806/9uiPTi5odYSj.png?imageslim" alt="mark"></p>
<ul>
<li>LCD屏幕<br>小熊派开发板板载LCD屏幕<strong>大小1.3寸，分辨率240*240，色彩深度16bit，使用ST7789V2液晶控制器</strong>。</li>
</ul>
<h2 id="软件准备"><a href="#软件准备" class="headerlink" title="软件准备"></a>软件准备</h2><ul>
<li>需要安装好Keil - MDK及芯片对应的包，以便编译和下载生成的代码；</li>
<li>准备一个串口调试助手，这里我使用的是<code>Serial Port Utility</code>；</li>
</ul>
<blockquote>
<p>Keil MDK和串口助手Serial Port Utility 的安装包都可以<strong>在文末关注公众号获取</strong>，回复关键字获取相应的安装包：</p>
</blockquote>
<p><img src="http://mculover666.cn/image/20190814/gubaOwmETp1w.png?imageslim" alt="mark"></p>
<h1 id="2-生成MDK工程"><a href="#2-生成MDK工程" class="headerlink" title="2.生成MDK工程"></a>2.生成MDK工程</h1><h2 id="选择芯片型号"><a href="#选择芯片型号" class="headerlink" title="选择芯片型号"></a>选择芯片型号</h2><p>打开STM32CubeMX，打开MCU选择器：<br><img src="http://mculover666.cn/image/20190806/gBP6glmUSH80.png?imageslim" alt="mark"></p>
<p>搜索并选中芯片<code>STM32L431RCT6</code>:<br><img src="http://mculover666.cn/image/20190806/gnyHwdl53uVD.png?imageslim" alt="mark"></p>
<h2 id="配置时钟源"><a href="#配置时钟源" class="headerlink" title="配置时钟源"></a>配置时钟源</h2><ul>
<li>如果选择使用外部高速时钟（HSE），则需要在System Core中配置RCC；</li>
<li>如果使用默认内部时钟（HSI），这一步可以略过；</li>
</ul>
<p>这里我都使用外部时钟：</p>
<p><img src="http://mculover666.cn/image/20190829/dBG4s5JFoXGM.png?imageslim" alt="mark"></p>
<h2 id="配置LCD控制GPIO"><a href="#配置LCD控制GPIO" class="headerlink" title="配置LCD控制GPIO"></a>配置LCD控制GPIO</h2><p><img src="http://mculover666.cn/image/20190829/4Y0g6NTXlmsc.png?imageslim" alt="mark"></p>
<h2 id="配置SPI2接口"><a href="#配置SPI2接口" class="headerlink" title="配置SPI2接口"></a>配置SPI2接口</h2><p>查看小熊派LCD接口的原理图：</p>
<p><img src="http://mculover666.cn/image/20190829/J5lfuBmdy0q2.png?imageslim" alt="mark"></p>
<p><img src="http://mculover666.cn/image/20190829/rIsAkWbeqWjH.png?imageslim" alt="mark"></p>
<p>引脚对应表如下：</p>
<table>
<thead>
<tr>
<th align="center">LCD引脚</th>
<th align="center">MCU引脚</th>
</tr>
</thead>
<tbody><tr>
<td align="center">SPI2_MOSI</td>
<td align="center">PC3</td>
</tr>
<tr>
<td align="center">SPI2_CLK</td>
<td align="center">PB13</td>
</tr>
<tr>
<td align="center">LCD_WR_RS</td>
<td align="center">PC6</td>
</tr>
<tr>
<td align="center">LCD_RESET</td>
<td align="center">PC7</td>
</tr>
<tr>
<td align="center">LCD_POWER</td>
<td align="center">PB15</td>
</tr>
</tbody></table>
<p>MCU只需要通过SPI向LCD控制器发送命令/数据即可，所以硬件上接 SPI2 的 SCK 和 MOSI 引脚，软件上将SPI2配置为发送主机模式，接下来开始配置SPI2接口：</p>
<p>参数设置如下：</p>
<p><img src="http://mculover666.cn/image/20190829/1DHh2ytSwgcp.png?imageslim" alt="mark"></p>
<p>SPI2默认SCK引脚是PB10，和开发板不对应，所以重新修改引脚为PB13：</p>
<p><img src="http://mculover666.cn/image/20190829/J0O0uJFSEap1.png?imageslim" alt="mark"></p>
<h2 id="配置时钟树"><a href="#配置时钟树" class="headerlink" title="配置时钟树"></a>配置时钟树</h2><p>STM32L4的最高主频到80M，所以配置PLL，最后使<code>HCLK = 80Mhz</code>即可：<br><img src="http://mculover666.cn/image/20190806/1TQg7frjRpVr.png?imageslim" alt="mark"></p>
<h2 id="生成工程设置"><a href="#生成工程设置" class="headerlink" title="生成工程设置"></a>生成工程设置</h2><p><img src="http://mculover666.cn/image/20190829/MQ6wAeYd1mMw.png?imageslim" alt="mark"></p>
<h2 id="代码生成设置"><a href="#代码生成设置" class="headerlink" title="代码生成设置"></a>代码生成设置</h2><p>最后设置生成独立的初始化文件：<br><img src="http://mculover666.cn/image/20190806/T6WvSK6Dfpts.png?imageslim" alt="mark"></p>
<h2 id="生成代码"><a href="#生成代码" class="headerlink" title="生成代码"></a>生成代码</h2><p>点击<code>GENERATE CODE</code>即可生成MDK-V5工程：<br><img src="http://mculover666.cn/image/20190806/s0jGhLBWW6Cm.png?imageslim" alt="mark"></p>
<h1 id="3-编写LCD驱动（ST7789）——-封装宏和底层函数"><a href="#3-编写LCD驱动（ST7789）——-封装宏和底层函数" class="headerlink" title="3. 编写LCD驱动（ST7789）—— 封装宏和底层函数"></a>3. 编写LCD驱动（ST7789）—— 封装宏和底层函数</h1><h2 id="3-1-封装控制LCD控制引脚高低电平的宏"><a href="#3-1-封装控制LCD控制引脚高低电平的宏" class="headerlink" title="3.1. 封装控制LCD控制引脚高低电平的宏"></a>3.1. 封装控制LCD控制引脚高低电平的宏</h2><p>控制引脚宏定义已经包含在 <code>main.h</code> 中，如图：</p>
<p><img src="http://mculover666.cn/image/20190829/X2Pj10IvIdq0.png?imageslim" alt="mark"></p>
<p>在编写驱动的过程中需要不断的控制这些控制引脚的电平，所以首先在 <code>lcd_spi2_drv.h</code> 头文件中编写控制这些引脚的宏：</p>
<pre class=" language-c"><code class="language-c"><span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"main.h"</span></span>

<span class="token macro property">#<span class="token directive keyword">define</span>    LCD_PWR(n)        (n?\
                        HAL_GPIO_WritePin(LCD_PWR_GPIO_Port,LCD_PWR_Pin,GPIO_PIN_SET):\
                        HAL_GPIO_WritePin(LCD_PWR_GPIO_Port,LCD_PWR_Pin,GPIO_PIN_RESET))</span>
<span class="token macro property">#<span class="token directive keyword">define</span>    LCD_WR_RS(n)    (n?\
                        HAL_GPIO_WritePin(LCD_WR_RS_GPIO_Port,LCD_WR_RS_Pin,GPIO_PIN_SET):\
                        HAL_GPIO_WritePin(LCD_WR_RS_GPIO_Port,LCD_WR_RS_Pin,GPIO_PIN_RESET))</span>
<span class="token macro property">#<span class="token directive keyword">define</span>    LCD_RST(n)        (n?\
                        HAL_GPIO_WritePin(LCD_RST_GPIO_Port,LCD_RST_Pin,GPIO_PIN_SET):\
                        HAL_GPIO_WritePin(LCD_RST_GPIO_Port,LCD_RST_Pin,GPIO_PIN_RESET))</span></code></pre>
<h2 id="3-2-宏定义屏幕分辨率和颜色值"><a href="#3-2-宏定义屏幕分辨率和颜色值" class="headerlink" title="3.2. 宏定义屏幕分辨率和颜色值"></a>3.2. 宏定义屏幕分辨率和颜色值</h2><pre class=" language-c"><code class="language-c"><span class="token comment" spellcheck="true">//LCD屏幕分辨率定义</span>
<span class="token macro property">#<span class="token directive keyword">define</span> LCD_Width   240</span>
<span class="token macro property">#<span class="token directive keyword">define</span> LCD_Height  240</span>
<span class="token comment" spellcheck="true">//颜色定义</span>
<span class="token macro property">#<span class="token directive keyword">define</span> WHITE   0xFFFF    </span><span class="token comment" spellcheck="true">//白色</span>
<span class="token macro property">#<span class="token directive keyword">define</span> YELLOW  0xFFE0    </span><span class="token comment" spellcheck="true">//黄色</span>
<span class="token macro property">#<span class="token directive keyword">define</span> BRRED   0XFC07  </span><span class="token comment" spellcheck="true">//棕红色</span>
<span class="token macro property">#<span class="token directive keyword">define</span> PINK    0XF81F    </span><span class="token comment" spellcheck="true">//粉色</span>
<span class="token macro property">#<span class="token directive keyword">define</span> RED     0xF800    </span><span class="token comment" spellcheck="true">//红色</span>
<span class="token macro property">#<span class="token directive keyword">define</span> BROWN   0XBC40  </span><span class="token comment" spellcheck="true">//棕色</span>
<span class="token macro property">#<span class="token directive keyword">define</span> GRAY    0X8430  </span><span class="token comment" spellcheck="true">//灰色</span>
<span class="token macro property">#<span class="token directive keyword">define</span> GBLUE   0X07FF    </span><span class="token comment" spellcheck="true">//兰色</span>
<span class="token macro property">#<span class="token directive keyword">define</span> GREEN   0x07E0    </span><span class="token comment" spellcheck="true">//绿色</span>
<span class="token macro property">#<span class="token directive keyword">define</span> BLUE    0x001F  </span><span class="token comment" spellcheck="true">//蓝色</span>
<span class="token macro property">#<span class="token directive keyword">define</span> BLACK   0x0000    </span><span class="token comment" spellcheck="true">//黑色</span></code></pre>
<p>接下来开始在 <code>lcd_spi2_drv.c</code> 编写驱动程序~</p>
<h2 id="3-3-封装LCD控制引脚初始化函数"><a href="#3-3-封装LCD控制引脚初始化函数" class="headerlink" title="3.3. 封装LCD控制引脚初始化函数"></a>3.3. 封装LCD控制引脚初始化函数</h2><p>首先包含必要的头文件：</p>
<pre class=" language-c"><code class="language-c"><span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"lcd_spi2_drv.h"</span></span>
<span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"gpio.h"</span></span>
<span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"spi.h"</span></span></code></pre>
<p>这个函数只能在本文件内由LCD初始化函数调用，所以使用static修饰为静态的：</p>
<pre class=" language-c"><code class="language-c"><span class="token comment" spellcheck="true">/**
 *@brief    LCD控制引脚和通信接口初始化
 *@param    none
 *@retval   none
*/</span>
<span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">LCD_GPIO_Init</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token comment" spellcheck="true">/* 初始化引脚 */</span>
    <span class="token function">MX_GPIO_Init</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment" spellcheck="true">/* 复位LCD */</span>
    <span class="token function">LCD_PWR</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_RST</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">HAL_Delay</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_RST</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment" spellcheck="true">/* 初始化SPI2接口 */</span>
    <span class="token function">MX_SPI2_Init</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<h2 id="3-4-封装LCD发送数据和发送命令函数"><a href="#3-4-封装LCD发送数据和发送命令函数" class="headerlink" title="3.4. 封装LCD发送数据和发送命令函数"></a>3.4. 封装LCD发送数据和发送命令函数</h2><p>数据都是由 SPI2 的MOSI发送，由 LCD_WR_RS 引脚指明该数据是命令还是数据。</p>
<p>首先在 <code>spi.c</code> 的最后调用HAL库封装一个函数，供驱动程序调用：</p>
<pre class=" language-c"><code class="language-c"><span class="token comment" spellcheck="true">/* USER CODE BEGIN 1 */</span>
<span class="token comment" spellcheck="true">/**
 * @brief    SPI 发送字节函数
 * @param    TxData    要发送的数据
 * @param    size    发送数据的字节大小
 * @return  0:写入成功,其他:写入失败
 */</span>
uint8_t <span class="token function">SPI_WriteByte</span><span class="token punctuation">(</span>uint8_t <span class="token operator">*</span>TxData<span class="token punctuation">,</span>uint16_t size<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">HAL_SPI_Transmit</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>hspi2<span class="token punctuation">,</span>TxData<span class="token punctuation">,</span>size<span class="token punctuation">,</span><span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">/* USER CODE END 1 */</span></code></pre>
<blockquote>
<p>不要忘了在spi.h中声明该函数！</p>
</blockquote>
<p>然后基于spi发送字节函数，在<strong>驱动文件中</strong>继续封装一个向LCD发送数据的函数，一个向LCD发送命令的函数：</p>
<pre class=" language-c"><code class="language-c"><span class="token comment" spellcheck="true">/**
 * @brief   写命令到LCD
 * @param   cmd —— 需要发送的命令
 * @return  none
 */</span>
<span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span>uint8_t cmd<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token function">LCD_WR_RS</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">SPI_WriteByte</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>cmd<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">/**
 * @brief   写数据到LCD
 * @param   dat —— 需要发送的数据
 * @return  none
 */</span>
<span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span>uint8_t dat<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token function">LCD_WR_RS</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">SPI_WriteByte</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>dat<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<h1 id="4-编写LCD驱动（ST7789）——-对照datasheet编程"><a href="#4-编写LCD驱动（ST7789）——-对照datasheet编程" class="headerlink" title="4. 编写LCD驱动（ST7789）—— 对照datasheet编程"></a>4. 编写LCD驱动（ST7789）—— 对照datasheet编程</h1><h2 id="4-1-打开-关闭背光函数"><a href="#4-1-打开-关闭背光函数" class="headerlink" title="4.1. 打开/关闭背光函数"></a>4.1. 打开/关闭背光函数</h2><p>这两个函数比较简单，直接调用控制LCD背光的引脚控制宏即可：</p>
<pre class=" language-c"><code class="language-c"><span class="token comment" spellcheck="true">/**
 * @breif   打开LCD显示背光
 * @param   none
 * @return  none
 */</span>
<span class="token keyword">void</span> <span class="token function">LCD_DisplayOn</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token function">LCD_PWR</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">/**
 * @brief   关闭LCD显示背光
 * @param   none
 * @return  none
 */</span>
<span class="token keyword">void</span> <span class="token function">LCD_DisplayOff</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token function">LCD_PWR</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<h2 id="4-2-指定显示RAM操作地址"><a href="#4-2-指定显示RAM操作地址" class="headerlink" title="4.2. 指定显示RAM操作地址"></a>4.2. 指定显示RAM操作地址</h2><p>根据数据手册，当要改变某个区域像素点的颜色时，首先应该确定X方向起始地址和X方向结束地址：</p>
<p><img src="http://mculover666.cn/image/20190829/SfifEyv85boN.png?imageslim" alt="mark"></p>
<p>然后确定Y方向起始地址和Y方向结束地址：</p>
<p><img src="http://mculover666.cn/image/20190829/zMRTyBS1Vv9j.png?imageslim" alt="mark"></p>
<p>最后再确定该区域内每个像素点的值(16bit)：</p>
<p><img src="http://mculover666.cn/image/20190829/0CfYcB8Xj56X.png?imageslim" alt="mark"></p>
<p>综上，我们每次操作的时候都需要指定操作区域，所以编写该函数：</p>
<pre class=" language-c"><code class="language-c"><span class="token comment" spellcheck="true">/**
 * @brief   设置数据写入LCD显存区域
 * @param   x1,y1    —— 起点坐标
 * @param   x2,y2    —— 终点坐标
 * @return  none
 */</span>
<span class="token keyword">void</span> <span class="token function">LCD_Address_Set</span><span class="token punctuation">(</span>uint16_t x1<span class="token punctuation">,</span> uint16_t y1<span class="token punctuation">,</span> uint16_t x2<span class="token punctuation">,</span> uint16_t y2<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token comment" spellcheck="true">/* 指定X方向操作区域 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0x2a</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span>x1 <span class="token operator">>></span> <span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span>x1<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span>x2 <span class="token operator">>></span> <span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span>x2<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment" spellcheck="true">/* 指定Y方向操作区域 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0x2b</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span>y1 <span class="token operator">>></span> <span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span>y1<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span>y2 <span class="token operator">>></span> <span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span>y2<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment" spellcheck="true">/* 发送该命令，LCD开始等待接收显存数据 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0x2C</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<h2 id="4-3-清屏函数"><a href="#4-3-清屏函数" class="headerlink" title="4.3. 清屏函数"></a>4.3. 清屏函数</h2><p>编写完指定显存操作区域后，趁热打铁，编写清屏函数就很简单啦，直接调用上面编写的函数，指定操作地址为全屏幕，然后循环发送颜色值即可：</p>
<pre class=" language-c"><code class="language-c"><span class="token macro property">#<span class="token directive keyword">define</span> LCD_TOTAL_BUF_SIZE    (240*240*2)</span>
<span class="token macro property">#<span class="token directive keyword">define</span> LCD_Buf_Size 1152</span>
<span class="token keyword">static</span> uint8_t lcd_buf<span class="token punctuation">[</span>LCD_Buf_Size<span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">/**
 * @brief   以一种颜色清空LCD屏
 * @param   color —— 清屏颜色(16bit)
 * @return  none
 */</span>
<span class="token keyword">void</span> <span class="token function">LCD_Clear</span><span class="token punctuation">(</span>uint16_t color<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    uint16_t i<span class="token punctuation">,</span> j<span class="token punctuation">;</span>
    uint8_t data<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">0</span><span class="token punctuation">}</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//color是16bit的，每个像素点需要两个字节的显存</span>

    <span class="token comment" spellcheck="true">/* 将16bit的color值分开为两个单独的字节 */</span>
    data<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> color <span class="token operator">>></span> <span class="token number">8</span><span class="token punctuation">;</span>
    data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span> color<span class="token punctuation">;</span>

    <span class="token comment" spellcheck="true">/* 显存的值需要逐字节写入 */</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span>j <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> LCD_Buf_Size <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">;</span> j<span class="token operator">++</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        lcd_buf<span class="token punctuation">[</span>j <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">]</span> <span class="token operator">=</span>  data<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        lcd_buf<span class="token punctuation">[</span>j <span class="token operator">*</span> <span class="token number">2</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span>  data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token comment" spellcheck="true">/* 指定显存操作地址为全屏幕 */</span>
    <span class="token function">LCD_Address_Set</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> LCD_Width <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">,</span> LCD_Height <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* 指定接下来的数据为数据 */</span>
    <span class="token function">LCD_WR_RS</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* 将显存缓冲区的数据全部写入缓冲区 */</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span>i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token punctuation">(</span>LCD_TOTAL_BUF_SIZE <span class="token operator">/</span> LCD_Buf_Size<span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token function">SPI_WriteByte</span><span class="token punctuation">(</span>lcd_buf<span class="token punctuation">,</span> <span class="token punctuation">(</span>uint16_t<span class="token punctuation">)</span>LCD_Buf_Size<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre>
<h2 id="4-4-LCD初始化函数"><a href="#4-4-LCD初始化函数" class="headerlink" title="4.4. LCD初始化函数"></a>4.4. LCD初始化函数</h2><p>至此，LCD的一些操作函数全部编写完成，最后编写初始化LCD模式的函数：</p>
<pre class=" language-c"><code class="language-c"><span class="token comment" spellcheck="true">/**
 * @brief   LCD初始化
 * @param   none
 * @return  none
 */</span>
<span class="token keyword">void</span> <span class="token function">LCD_Init</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token comment" spellcheck="true">/* 初始化和LCD通信的引脚 */</span>
    <span class="token function">LCD_GPIO_Init</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">HAL_Delay</span><span class="token punctuation">(</span><span class="token number">120</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment" spellcheck="true">/* 关闭睡眠模式 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0x11</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">HAL_Delay</span><span class="token punctuation">(</span><span class="token number">120</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment" spellcheck="true">/* 开始设置显存扫描模式，数据格式等 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0x36</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x00</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* RGB 5-6-5-bit格式  */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0x3A</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x65</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* porch 设置 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xB2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x0C</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x0C</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x00</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x33</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x33</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* VGH设置 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xB7</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x72</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* VCOM 设置 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xBB</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x3D</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* LCM 设置 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xC0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x2C</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* VDV and VRH 设置 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xC2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x01</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* VRH 设置 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xC3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x19</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* VDV 设置 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xC4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x20</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* 普通模式下显存速率设置 60Mhz */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xC6</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x0F</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* 电源控制 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xD0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0xA4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0xA1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* 电压设置 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xE0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0xD0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x04</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x0D</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x11</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x13</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x2B</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x3F</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x54</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x4C</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x18</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x0D</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x0B</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x1F</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x23</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* 电压设置 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0xE1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0xD0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x04</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x0C</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x11</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x13</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x2C</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x3F</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x44</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x51</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x2F</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x1F</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x1F</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x20</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Data</span><span class="token punctuation">(</span><span class="token number">0x23</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/* 显示开 */</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0x21</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">LCD_Write_Cmd</span><span class="token punctuation">(</span><span class="token number">0x29</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment" spellcheck="true">/* 清屏为白色 */</span>
    <span class="token function">LCD_Clear</span><span class="token punctuation">(</span>WHITE<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment" spellcheck="true">/*打开显示*/</span>
    <span class="token function">LCD_PWR</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>至此，驱动编写完成。</p>
<h1 id="5-测试驱动程序"><a href="#5-测试驱动程序" class="headerlink" title="5. 测试驱动程序"></a>5. 测试驱动程序</h1><p>在 <code>main函数</code> 中编写驱动测试代码，在 <code>while(1)</code> 之前添加如下代码：</p>
<pre class=" language-c"><code class="language-c">  <span class="token comment" spellcheck="true">/* USER CODE BEGIN 2 */</span>
  <span class="token function">LCD_Init</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token function">LCD_Clear</span><span class="token punctuation">(</span>GREEN<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token comment" spellcheck="true">/* USER CODE END 2 */</span></code></pre>
<p>测试结果如图：</p>
<p><img src="http://mculover666.cn/image/20190829/2rf6XcYSMCAE.png?imageslim" alt="mark"></p>
<p>绿绿的，是不是很好看哈哈(斜眼笑.jpg)~</p>
<p>至此，我们已经学会<strong>如何使用硬件SPI驱动LCD屏幕（ST7789）</strong>，下一节将讲述如何使用硬件QSPI接口读写SPI Flash的数据。</p>
<p><strong><font color="#FF0000">更多精彩文章及资源，请关注我的微信公众号：『mculover666』。</font></strong></p>
<p><img src="http://mculover666.cn/image/20190814/NQqt1eRxrl1K.png?imageslim" alt="mark"></p>

            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="http://www.mculover666.cn" rel="external nofollow noreferrer">Mculover666</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="http://www.mculover666.cn/posts/4251315252/">http://www.mculover666.cn/posts/4251315252/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="http://www.mculover666.cn" target="_blank">Mculover666</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/STM32CubeMX-TFT-LCD-SPI%E6%80%BB%E7%BA%BF/">
                                    <span class="chip bg-color">STM32CubeMX TFT-LCD SPI总线</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    
    <div class="social-share" data-sites="qq,qzone,wechat,weibo,douban" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.png" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/we-chat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>
            
        </div>
    </div>

    

    

    

    
    <div class="livere-card card" data-aos="fade-up">
    <!-- 来必力City版安装代码 -->
    <div id="lv-container" class="card-content" data-id="city" data-uid="MTAyMC80Njg0OS8yMzM1MA">
        <script type="text/javascript">
            (function (d, s) {
                let j, e = d.getElementsByTagName(s)[0];
                if (typeof LivereTower === 'function') {
                    return;
                }

                j = d.createElement(s);
                j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
                j.async = true;

                e.parentNode.insertBefore(j, e);
            })(document, 'script');
        </script>
        <noscript>为正常使用来必力评论功能请激活JavaScript。</noscript>
    </div>
    <!-- City版安装代码已完成 -->
</div>
    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/posts/1294047065/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/9.jpg" class="responsive-img" alt="STM32CubeMX-18 | 使用硬件QSPI读写SPI Flash（W25Q64）">
                        
                        <span class="card-title">STM32CubeMX-18 | 使用硬件QSPI读写SPI Flash（W25Q64）</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            本篇详细的记录了如何使用STM32CubeMX配置STM32L431RCT6的硬件QSPI外设与 SPI Flash 通信（W25Q64）。


1. 准备工作硬件准备
开发板首先需要准备一个开发板，这里我准备的是STM32L4的开发板（B
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2019-08-08
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/STM32CubeMX/" class="post-category">
                                    STM32CubeMX
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/STM32CubeMX-SPI-Flash-QSPI%E6%8E%A5%E5%8F%A3/">
                        <span class="chip bg-color">STM32CubeMX SPI Flash QSPI接口</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/posts/1935373145/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/16.jpg" class="responsive-img" alt="如何通俗的理解CRC校验并用C语言实现">
                        
                        <span class="card-title">如何通俗的理解CRC校验并用C语言实现</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            本篇文章通俗的讲解了何谓CRC？如何生成CRC码以及如何使用CRC码校验，最后采用多种思路用C语言实现CRC校验。



背景最近在研究温湿度传感器SHT30，该传感器使用IIC接口进行通信，在读取数据时，该传感器分别在发送 16bit 的
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2019-08-06
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E7%AE%97%E6%B3%95/" class="post-category">
                                    算法
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/CRC%E6%A0%A1%E9%AA%8C%E7%AE%97%E6%B3%95/">
                        <span class="chip bg-color">CRC校验算法</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h1, h2, h3, h4, h5, h6'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h1, h2, h3, h4, h5, h6').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>



    <footer class="page-footer bg-color">
    
    <div class="container row center-align" style="margin-bottom: 15px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">2016</span>
            <a href="http://www.mculover666.cn" target="_blank">Mculover666</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">70.7k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <span id="sitetime">载入运行时间...</span>
            <script>
                function siteTime() {
                    var seconds = 1000;
                    var minutes = seconds * 60;
                    var hours = minutes * 60;
                    var days = hours * 24;
                    var years = days * 365;
                    var today = new Date();
                    var startYear = "2016";
                    var startMonth = "08";
                    var startDate = "28";
                    var startHour = "0";
                    var startMinute = "0";
                    var startSecond = "0";
                    var todayYear = today.getFullYear();
                    var todayMonth = today.getMonth() + 1;
                    var todayDate = today.getDate();
                    var todayHour = today.getHours();
                    var todayMinute = today.getMinutes();
                    var todaySecond = today.getSeconds();
                    var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                    var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                    var diff = t2 - t1;
                    var diffYears = Math.floor(diff / years);
                    var diffDays = Math.floor((diff / days) - diffYears * 365);
                    var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
                    var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
                        minutes);
                    var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours -
                        diffMinutes * minutes) / seconds);
                    if (startYear == todayYear) {
                        document.getElementById("year").innerHTML = todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffDays + " 天 " + diffHours +
                            " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    } else {
                        document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffYears + " 年 " + diffDays +
                            " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    }
                }
                setInterval(siteTime, 1000);
            </script>
            
            <br>
            
            <span id="icp"><img src="/medias/icp.png" style="vertical-align: text-bottom;" />
                <a href="http://www.beian.miit.gov.cn" target="_blank">陇ICP备19002222号</a>
            </span>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/Mculover666" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:mculover666@foxmail.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=2412828003" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 2412828003" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>





    <a href="https://www.zhihu.com/people/wang-shi-wei-67-38/activities" class="tooltipped" target="_blank" data-tooltip="关注我的知乎: https://www.zhihu.com/people/wang-shi-wei-67-38/activities" data-position="top" data-delay="50">
        <i class="fab fa-zhihu1">知</i>
    </a>



    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Global site tag (gtag.js) - Google Analytics -->


    <!-- Baidu Analytics -->

<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?6e1efa0988723a1db6356535db2ae6bd";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    
    <script type="text/javascript" src="/libs/background/ribbon-dynamic.js" async="async"></script>
    
    
    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
